#include "imagegraphicsitem.h"
#include <QDebug>
#include "debug.h"

ImageGraphicsItem::ImageGraphicsItem(int id)
    :mNeedUpate(true),
      mLockImage(0),
      mId(id)
{

}

ImageGraphicsItem::~ImageGraphicsItem()
{

}

QRectF ImageGraphicsItem::boundingRect() const
{
    return QRectF(0, 0, 1920, 1080);
}

//QPainterPath ImageGraphicsItem::shape() const
//{
//    QPainterPath path;
//    path.addRect(14, 14, 82, 42);
//    return path;
//}

void ImageGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(widget);
    //    qDebug()<<"paint item path is "<<mImagePath<<"current id is " << mId;

    int ret = mLockImage->startReadLock(mTempImage);
//    qDebug()<<"paint id" <<mId<<&mTempImage;
    if(ret >= 0){
        //        ENTER_WITH_IME(QString("draw %1").arg(mId))
        if(!mTempImage.isNull()) {
            painter->drawImage(QPoint(0, 0), mTempImage);
//            qDebug()<<"real draw "<<mId;
        } else {
            qDebug()<<"wrong draw"<<mId;
        }
        //        EXIT_PRINT_TIME(QString("draw %1").arg(mId))
        mLockImage->stopReadLock(ret);
    }
}

void ImageGraphicsItem::setLockImage(LockImage *img)
{
    mLockImage = img;
}

